package com.gopay.common.cps.dao.fund.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.fund.BindCardInfoDAO;
import com.gopay.common.domain.fund.FundGopayBankcardInfoEntity;
import com.gopay.common.domain.fund.FundGopayCardEntity;
import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;
/**
 * @BindCardDAOImpl.java
 * @author baiyunpeng
 * @2016年7月4日 上午10:27:00  www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("bindCardInfoDAO")
public class BindCardInfoDAOImpl extends BaseDAOImpl<FundGopayBankcardInfoEntity, String> implements BindCardInfoDAO{
    @Override
    public FundGopayBankcardInfoEntity save(FundGopayBankcardInfoEntity entity) {
        if(entity!=null) {
            super.save(entity);
            return entity;
        }
        return null;
    }
    @Override
    public FundGopayBankcardInfoEntity findByCriteria(String agentSignNo,String type) {
        DetachedCriteria deCriteria = DetachedCriteria.forClass(FundGopayBankcardInfoEntity.class);
        if(StringUtils.isNotBlank(agentSignNo)){
            deCriteria.add(Restrictions.eq("agentSignNo",agentSignNo));
        }
        if(StringUtils.isNotBlank(type) && "1".equals(type)){
            deCriteria.add(Restrictions.eq("type",type));
        }
        List<FundGopayBankcardInfoEntity> list = getHibernateTemplate().findByCriteria(deCriteria);
        if(list!=null && list.size()>0){
            return list.get(0);
        }
        return null;
    }
}
